package colleaction.efficiency;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 测试集合遍历效率
 * 
 * @author User
 * 
 */
public class CollectionIterate {

	private static Map<Integer, Name> nameMap = new HashMap<Integer, Name>();
	private static List<Name> nameList = new ArrayList<Name>();

	public static void main(String[] args) {

		init();

		long tick = System.currentTimeMillis();
		// for (int i = 0; i < 1000; i++) {
		// getAllNames();
		// }

		// for (Name name : getAllNames()) {
		// name.getLastName();
		// }

//		 for (Name name : nameList) {
//		
//		 }
//
		 for (int i = 0, len = nameList.size(); i < len; i++) {
		
		 }

		System.out.println(System.currentTimeMillis() - tick);

	}

	private static void init() {
		for (int i = 0; i < 1000; i++) {
			// nameMap.put(i, new Name("first" + i, "last" + i));

			nameList.add(new Name("first", "last"));
		}
	}

	private static Collection<Name> getAllNames() {

		System.out.println("==========");
		Collection<Name> temp = new ArrayList<Name>();
		temp.addAll(nameMap.values());

		return nameMap.values();
	}

}

class Name {
	private String firstName;
	private String lastName;

	public Name(String firstName, String lastName) {
		super();
		this.firstName = firstName;
		this.lastName = lastName;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

}
